package com.wyb.controller;

import com.wyb.mapper.ArticleMapper;
import com.wyb.pojo.Article;
import com.wyb.constant.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/myarticles")
public class GetArticles {

    @Autowired
    private ArticleMapper articleMapper;

    //获取我的文章
    @GetMapping
    public Result getMyArticles(@RequestParam int id){

        List<Article> articles = articleMapper.selectListByUserId(id);
        boolean empty = articles.isEmpty();
        return !empty? new Result(200, "用户成功获取文章", articles)
                     : new Result(201, "你还没有写文章", null);
    }


}
